package hu.blok1.veilingsite.server;

import hu.blok1.veilingsite.shared.Address;
import hu.blok1.veilingsite.shared.User;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GetUserObject {

	public static User GetSingleUser(ResultSet result) {
		User user = new User();
		try {
			while (result.next()) {

				user.setId(result.getInt("id"));
				user.setName(result.getString("name"));
				user.setLastName(result.getString("lastname"));
				user.setEmail(result.getString("email"));
				user.setPassword(result.getString("password"));
				user.setRegisterDate(result.getDate("register_date"));
				user.setUserType(result.getString("usertype"));
				user.setBankAccount(result.getString("bankaccount"));
				user.setCredits(result.getInt("credits"));
				user.setStatus(result.getString("status"));
				user.setAddressId(result.getInt("fk_address_id"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return user;
	}
	
	public static Address GetAddress(ResultSet result) {
		Address  adres = new Address();
		try {
			while (result.next()) {
				adres.setId(result.getInt("id"));
				adres.setStreet(result.getString("streetname"));
				adres.setHouseNumber(result.getString("housenumber"));
				adres.setCity(result.getString("place"));
				adres.setCountry(result.getString("country"));
				adres.setPhoneNumber(result.getString("phonenumber"));
				adres.setPostCode(result.getString("postcode"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return adres;
	}


	public static List<User> GetMultiUser(ResultSet result) {
		List<User> userList = new ArrayList<User>();

		try {
			while (result.next()) {
				User user = new User();
				user.setId(result.getInt("id"));
				user.setName(result.getString("name"));
				user.setLastName(result.getString("lastname"));
				user.setEmail(result.getString("email"));
				user.setPassword(result.getString("password"));
				user.setRegisterDate(result.getDate("register_date"));
				user.setUserType(result.getString("usertype"));
				user.setBankAccount(result.getString("bankaccount"));
				user.setCredits(result.getInt("credits"));
				user.setStatus(result.getString("status"));
				user.setAddressId(result.getInt("fk_address_id"));
				userList.add(user);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return userList;
	}
}
